(function($) {
  // center a modal window
  $.fn.center = function () {
  	var display = $(this).css('display');
  	$(this).css({'display': 'block'});

    this.css("position","absolute");
  	var parentOffset =  $(this).offsetParent().offset();
    this.css("top", ( $(window).height() - this.height() ) / 2 - parentOffset.top + $(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2 - parentOffset.left + $(window).scrollLeft() + "px");

  	$(this).css({'display': display});

    return this;
  };
      
})(jQuery);